<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
	xmlns:mo="https://gitee.com/pylpyl/LING">
<head
	th:replace="/common/template :: header(~{::title},~{::link},~{::style})">
<link rel="stylesheet" th:href="@{/css/code.css}">
<link rel="stylesheet" th:href="@{/plugin/inputTags.css}">
</head>
<body class="ling-layout-page">
	<div class="layui-card">
		<div class="layui-card-header ling-card-header">
			<span><i class="fa fa-bars"></i> 代码生成</span> <i
				class="layui-icon layui-icon-refresh refresh-btn" style="left: 92px"></i>
		</div>
		<div class="layui-card-body">
			<fieldset id="basic" class="layui-elem-field">
				<legend class="code-legend">基本信息</legend>
				<div class="layui-field-box">
				<div class="layui-form">
					<div class="layui-form-item">
							<label class="layui-form-label required">作者名称</label>
							<div class="layui-input-block">
								<input type="text" name="author" value="灵魂贰婶" autocomplete="off"
									class="layui-input">
							</div>
					</div>
					<div class="layui-form-item">
							<label class="layui-form-label required">保存路径</label>
							<div class="layui-input-block">
								<input type="text" name="location" value="D://"
									autocomplete="off" class="layui-input">
							</div>
					</div>
					<div class="layui-form-item">
							<label class="layui-form-label required">驱动类名</label>
							<div class="layui-input-block">
								<input type="text" name="jdbcDriver"
									value="com.mysql.cj.jdbc.Driver" autocomplete="off"
									class="layui-input">
							</div>
					</div>
					<div class="layui-form-item">
							<label class="layui-form-label required">数据库url</label>
							<div class="layui-input-block">
								<input type="text" name="jdbcUrl"
									value="jdbc:mysql://127.0.0.1:3306/ling?serverTimezone=GMT%2B8"
									autocomplete="off" class="layui-input">
							</div>
					</div>
					<div class="layui-form-item">
							<label class="layui-form-label required">用户名</label>
							<div class="layui-input-block">
								<input type="text" name="user" value="root" autocomplete="off"
									class="layui-input">
							</div>
					</div>
					<div class="layui-form-item">
							<label class="layui-form-label required">密码</label>
							<div class="layui-input-block">
								<input type="text" name="password" value="root"
									autocomplete="off" class="layui-input">
							</div>

					</div>
					<div class="layui-form-item">
							<label class="layui-form-label required">模块名</label>
							<div class="layui-input-block">
								<input type="text" name="basepackage" value="com.pyl."
									autocomplete="off" class="layui-input"> <span
									style="color: red;">类似：com.pyl.XXX.(最后以 . 结尾)</span>
							</div>
					</div>
				</div>
					
				</div>
			</fieldset>
		</div>
	</div>
	<div class="layui-card">
		<div class="layui-card-header">
			<span><i class="fa fa-bars"></i> 表单输入</span>
		</div>
		<div class="layui-card-body">
			<div class="tags" id="tags">
				<input type="text" name="" style="outline: none; border-width: 0"
					id="tables" placeholder="回车生成数据表" autocomplete="off">
			</div>
			<button class=" albtn layui-btn  layui-btn-lg layui-btn-warm"
				id="submit" th:attr="data-url=@{/dev/code/save}">开始逆向</button>
		</div>
	</div>
	<script th:replace="/common/template :: script"></script>
	<script type="text/javascript"
		th:src="@{/js/plugins/jquery-3.3.1.min.js}"></script>
	<script type="text/javascript" th:inline="javascript">
		layui.extend({ //设定模块别名
			inputTags : [[@{/plugin/inputTags}]] //如果 mymod.js 是在根目录，也可以不用设定别名
		});
		layui.use([ 'inputTags','jquery','layer' ], function() {
			var inputTags = layui.inputTags;
			var $ = layui.jquery;
			inputTags.render({
				elem : '#tables',
				aldaBtn : false,
				submit : '#submit',
				submitFunction : function(content) {
					var formdata = getData();
					formdata.append("tables",content.join(","));
					var url = $("#submit").attr("data-url");
					var lode = layer.open({type: 3});
					$.ajax({
	                    url: url,
	                    type: "POST",
	                    data: formdata,
	                    contentType: false,
	                    processData: false,
	                    success: function (result) {
	                    	layer.close(lode);
	                        if (result.code === 200) {
	                            layer.msg(result.msg, {offset: '15px', time: 2000, icon: 1});
	                        } else {
	                            layer.msg(result.msg, {offset: '15px', time: 3000, icon: 2});
	                        }
	                    }
	                });
				}
			});

			function getData() {
				var formdata = new FormData();
				formdata.append("author", $("input[name='author']").val());
				formdata.append("location", $("input[name='location']").val());
				formdata.append("jdbcDriver", $("input[name='jdbcDriver']").val());
				formdata.append("jdbcUrl", $("input[name='jdbcUrl']").val());
				formdata.append("user", $("input[name='user']").val());
				formdata.append("password", $("input[name='password']").val());
				formdata.append("basepackage", $("input[name='basepackage']").val());
				return formdata
			};

		})
	</script>
</body>
</html>